package com.music.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.music.dao.SingerMapper;
import com.music.dao.UserMapper;
import com.music.entity.Admin;
import com.music.entity.Singer;
import com.music.service.SingerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
@Slf4j
public class SingServiceImpl implements SingerService {
    @Autowired
    private SingerMapper singerMapper;

    @Override
    public List<Singer> findByCondition(Singer singer) {
        List<Singer> list=new ArrayList<Singer>();
        list=singerMapper.SelectByCondition(singer);
        return list;
    }

    /**
     * 林鑫海
     * @param pageNum
     * @param pageSize
     * @param singer
     * @return
     */
    @Override
    public PageInfo<Singer> getSingerByPage(int pageNum, int pageSize, Singer singer) {
        StringBuffer singerName = new StringBuffer();
        // 判断参数情况，拼接字符串匹配符%
        if (singer.getSingerName() != null && !"".equals(singer.getSingerName())) {
            // 进行管理员账号关键字查询
            singerName.append("%").append(singer.getSingerName()).append("%");// where A.SingerName like '%歌手账号%';
            // 重新设值
            singer.setSingerName(singerName.toString());
        }
        //开始分页
        PageHelper.startPage(pageNum,pageSize);
        //执行select查询语句
        List<Singer> pageSelective = singerMapper.findPageSelective(singer);
        //封装分页对象
        PageInfo<Singer> pageInfo = new PageInfo<>(pageSelective);
        return pageInfo;
    }

    /**
     * 林鑫海
     * @param singer
     * @return
     */
    @Override
    public boolean addSinger(Singer singer) {
        return singerMapper.byInsert(singer)>0;
    }

    /**
     * 林鑫海
     * @param singer
     * @return
     */
    @Override
    public boolean modifySinger(Singer singer) {
        return singerMapper.byUpdate(singer)>0;
    }
}
